package com.boang.lock;

/*
    @author:sa
    @date:2024/11/26 13:58
*/
public class TicketDemoSys03 implements Runnable {
    private int num = 20;
    private Object lock = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (lock) {
                if (num > 0) {
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    System.out.println(Thread.currentThread().getName() + ":" + num--);
                }
            }
        }
    }
}